﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using System.Data;

namespace WAD.DAL
{
    public class DAOAdmin : DAO
    {
        public static Dictionary<string, object> Get(int id)
        {
            return WAD.DAL.DAO.Get("admin", "id=" + id);
        }
        public static int Edit(int id, string password, string truename, int groupid, string groupname, int state)
        {
            String sql = "update [admin](password,groupid,groupname,updatetime,state)values(@password,@groupid,@groupname,getdate(),@state) where id=@id";
            Database db = GetDatabase();
            DbCommand cmd = db.GetSqlStringCommand(sql);
            db.AddInParameter(cmd, "@password", DbType.String, password);
            db.AddInParameter(cmd, "@groupid", DbType.Int32, groupid);
            db.AddInParameter(cmd, "@groupname", DbType.String, groupname);
            db.AddInParameter(cmd, "@updatetime", DbType.DateTime, DateTime.Now);
            db.AddInParameter(cmd, "@state", DbType.Int32, state);
            return db.ExecuteNonQuery(cmd);
        }

        public static int EditPass(int id, string password)
        {
            String sql = "update [admin] set password=@password where id=@id";
            Database db = GetDatabase();
            DbCommand cmd = db.GetSqlStringCommand(sql);
            db.AddInParameter(cmd, "@password", DbType.String, password);
            db.AddInParameter(cmd, "@id", DbType.Int32, id);
            return db.ExecuteNonQuery(cmd);
        }
    }
}